package cn.woniu.ecommerceplatform.controller;

import cn.woniu.ecommerceplatform.entity.Goods;
import cn.woniu.ecommerceplatform.service.GoodsService;
import cn.woniu.ecommerceplatform.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author NCQ
 * @date 2023/1/5
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @RequestMapping("/goodslist")
    public ResponseResult<?> goodslist(String goodName,String goodCode,Integer shelfStatus,Integer pageNum,Integer pageSize){
        return goodsService.goodsList(goodName,goodCode,shelfStatus,pageNum,pageSize);
    }
    @RequestMapping("/queryGoods")
    public ResponseResult<?> queryGoods(String goodName,Integer typeId,Integer pageNum,Integer pageSize){
        return goodsService.queryGoods(goodName,typeId,pageNum,pageSize);
    }
    @PostMapping("/goodAdd")
    @PreAuthorize("hasAnyAuthority('good:add')")
    public ResponseResult<?> goodadd(@RequestBody Goods goods){
        return goodsService.goodAdd(goods);
    }
    @RequestMapping("/goodDelete")
    @PreAuthorize("hasAnyAuthority('good:delete')")
    public ResponseResult<?> gooddelete( Integer id){
        return goodsService.goodDelete(id);
    }
    @PostMapping("/goodUpdate")
    @PreAuthorize("hasAnyAuthority('good:update')")
    public ResponseResult<?> goodUpdate(@RequestBody Goods goods){
        return goodsService.goodUpdate(goods);
    }
    @PostMapping("/goodsDelete")
    @PreAuthorize("hasAnyAuthority('good:delete')")
    public ResponseResult<?> goodsDelete(@RequestBody Integer[] ids){
        return goodsService.goodsDelete(ids);
    }
    @PostMapping("/goodsAddShelf")
    @PreAuthorize("hasAnyAuthority('good:update')")
    public ResponseResult<?> goodAddShelf(@RequestBody Integer[] ids){
        return goodsService.addShelf(ids);
    }
    @PostMapping("/goodsDeleteShelf")
    @PreAuthorize("hasAnyAuthority('good:update')")
    public ResponseResult<?> goodDeleteShelf(@RequestBody Integer[] ids){
        return goodsService.deleteShelf(ids);
    }
    @RequestMapping("/goodById")
    @PreAuthorize("hasAnyAuthority('good:query')")
    public ResponseResult<?> goodById(Integer id){
        return goodsService.queryGoodById(id);
    }

    /**
     * 积分商城接口
     */
    @RequestMapping("/pointGoodsList")
    public ResponseResult<?> pointGoodsList(String goodName,Integer pageNum,Integer pageSize){
        return goodsService.queryPG(goodName,pageNum,pageSize);
    }
}
